package com.contacto.controller;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.contacto.domain.Contacto;
import com.contacto.service.ContactoService;

@Controller
@RequestMapping(value = "/contacto")
public class ContactoController {
	
	@Autowired
	ContactoService contactoService;

	@RequestMapping(value = "/{nombre}", method = RequestMethod.GET)
	@ResponseBody
	public Collection<Contacto> buscarPorNombre(@PathVariable String nombre) {
		return contactoService.buscarPorNombre(nombre);
	}

	@RequestMapping(method = RequestMethod.POST)
	@ResponseBody
	@ResponseStatus(HttpStatus.CREATED)
	public Contacto agregar(@RequestBody Contacto contacto) {
		contactoService.agregar(contacto);
		return contacto;
	}

}
